package com.easy.dfcapi.web;

import com.easy.common.bean.Result;
import com.easy.common.constant.EnumConfig;
import com.easy.common.util.IPUtil;
import com.easy.core.web.Api20Controller;
import com.easy.dfcapi.res.ActivityEnrollQueryRes;
import com.easy.dfcapi.res.BuyerUserRes;
import com.easy.dfcapi.res.Product;
import com.easy.dfcapi.res.Response;
import com.easy.dfcapi.service.ApiBuyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 活动相关控制器
 */

@Controller
@RequestMapping(value = "${apiPath}/2.0/buyer")
public class ApiBuyerController extends Api20Controller {


    @Autowired
    private ApiBuyerService buyerService;

    /**
     * 买家版首页
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HomePage")
    public Result HomePage() {
        try {
            return buyerService.HomePage();
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 买家版首页
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "NiceProduct", method = RequestMethod.POST)
    public Result NiceProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            return buyerService.NiceProduct(response);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 品牌馆/潮流馆-本周最大牌
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "BestOnWeek", method = RequestMethod.POST)
    public Result BestOnWeek(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.BestOnWeek(response);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 品牌馆/潮流馆-Banner
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "Banner", method = RequestMethod.POST)
    public Result Banner(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.Banner(response);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
    /**
     * 品牌馆/潮流馆-今日我大牌
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "BestToday", method = RequestMethod.POST)
    public Result BestToday(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.BestToday(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
    /**
     * 品牌馆/潮流馆-今日我大牌更多。
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "BestTodayMore", method = RequestMethod.POST)
    public Result BestTodayMore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.BestTodayMore(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }


    /**
     * 品牌馆/潮流馆-今日我最爆
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "BestProductToday", method = RequestMethod.POST)
    public Result BestProductToday(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.BestProductToday(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }



    /**
     * 童品汇首页-商家列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "TPFactoryList", method = RequestMethod.POST)
    public Result TPFactoryList(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.TPFactoryList(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 童品汇首页-商品列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "TPBestProduct", method = RequestMethod.POST)
    public Result TPBestProduct(Response<Product> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.TPBestProduct(response);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 尾品汇首页-商家列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "WPFactoryList", method = RequestMethod.POST)
    public Result WPFactoryList(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.WPFactoryList(response);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 尾品汇首页-商品列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "WPBestProduct", method = RequestMethod.POST)
    public Result WPBestProduct(Response<Product> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.WPBestProduct(response);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 尾品汇首页-今日抢购、明日预告
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "WPProduct", method = RequestMethod.POST)
    public Result WPProduct(Response<Product> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.WPProduct(response);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }


    /**
     * 天天焕新
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DayDayProduct", method = RequestMethod.POST)
    public Result DayDayProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.DayDayProduct(response);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 好厂推荐
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "NiceFactory", method = RequestMethod.POST)
    public Result NiceFactory(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.NiceFactory(response);
        } catch (Exception e) {
            Result rt = new Result();
            System.out.println("Error:"+e.toString());
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }


    /**
     * 天天特价首页
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DaySpecialOffer", method = RequestMethod.POST)
    public Result DaySpecialOffer(Response<Product> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.DaySpecialOffer(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 天天特价更多
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DaySpecialOfferMore", method = RequestMethod.POST)
    public Result DaySpecialOfferMore(Response<Product> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.DaySpecialOfferMore(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 订货会首页
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "OrderMeeting", method = RequestMethod.POST)
    public Result OrderMeeting(Response<ActivityEnrollQueryRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.OrderMeeting(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 订货会详情
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "OrderMeetingDetail", method = RequestMethod.POST)
    public Result OrderMeetingDetail(Response<ActivityEnrollQueryRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.OrderMeetingDetail(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 订货会详情列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "OrderMeetingDetailProduct", method = RequestMethod.POST)
    public Result OrderMeetingDetailProduct(Response<ActivityEnrollQueryRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.OrderMeetingDetailProduct(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }

    /**
     * 聚爆款首页
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "ImplosionList", method = RequestMethod.POST)
    public Result ImplosionList(Response<Product> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.ImplosionList(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
    /**
     * 跳尾货场次
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "JumpTailTime", method = RequestMethod.POST)
    public Result JumpTailTime(Response<Product> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.JumpTailTime(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
    /**
     * 跳尾货场次列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "JumpTailList", method = RequestMethod.POST)
    public Result JumpTailList(Response<Product> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return buyerService.JumpTailList(response);
        } catch (Exception e) {
            System.out.println("Error:"+e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
}
